package graphic;
import presenter.Presenter;


public class ControlGUI {

	
	private ChatWindow chat;
	private ConnectWindow connect;
	private Presenter p;
	private Thread tChat;
	private Thread tConnect;
	private boolean connected;
	
	public ControlGUI(Presenter pr){
		this.p = pr;
		this.connected = false;
		this.chat = new ChatWindow(this);
		chat.setVisible(false);
		chat.setEdit(false);
		this.connect = new ConnectWindow(this);
		(tConnect = new Thread(connect)).start();
		tChat = new Thread(chat);
	}
	
	
	
	public boolean getConnected(){
		return this.connected;
	}
	    
    public void showLocalConnect(String login) {
    	connect.setVisible(false);
    	connect.setEdit(false);
    	connected = true;
    	chat.setVisible(true);
    	chat.setEdit(true);
    	tChat.run();
    	chat.showLocalConnect(login);
	}
	    
    public void showConnect(String login){
    	chat.showConnect(login);
    }
	    
    public void showLocalDisconnect() {
    	chat.showLocalDisconnect();
    	chat.setVisible(false);
    	chat.setEdit(false);
    	connect.setVisible(true);
    	connect.setEdit(true);
    	connected = false;
    	tConnect.run();
	}
	    
    public void showDisconnect(String login){
    	chat.showDisconnect(login);
    }
	    
    public void showText(String login, String text){
    	chat.showText(login, text);
    }
    
    public void showPropFile(String fileName, long fileSize, int fileID,
			String login) {
		chat.showPropFile(fileName,fileSize,fileID,login);
		
	}
    
	    
    public void performConnect(String login){
    	tConnect.interrupt();
    	p.performConnect(login);
    }
    
    public void performDisconnect() {
    	tChat.interrupt();
    	p.performDisconnect();
    }
    
    public void performSendText(String[] users, String text){
    	p.performSendText(text, users);
    }

    public void performPropFile (String fileName, long fileSize,String login, String path) {
    	p.performPropFile(fileName, fileSize,login, path);
    }

	public void performAcceptFile(int fileID, boolean accepted, boolean now, String login, String path) {
		p.performAcceptFile(fileID,accepted,now,login,path);
		
	}



    
	
}
